<template>
    <div class="container">
        <div class="title">
            <span>添加</span>
            <span class="back" @click="back">
        <i class="iconfont icon-fanhui"></i> 返回
      </span>
        </div>
        <el-divider></el-divider>
        <br/>
        <el-form label-width="100px"
                 :model="form"
                 status-icon
                 ref="form"
                 @submit.native.prevent>
            <el-form-item label="标题" prop="title">
                <el-input size="medium" v-model="form.title" placeholder="请填写标题"></el-input>
            </el-form-item>
           <el-form-item label="类型" prop="typeid">
                <el-radio v-model="form.typeid" label="1">文字</el-radio>
                <el-radio v-model="form.typeid" label="2">图文</el-radio>
            </el-form-item>
            <el-form-item label="回复时机" prop="status">
                <el-select v-model="form.status" placeholder="请选择回复时机">
                    <el-option
                            v-for="item in status_arr"
                            :label="item.name"
                            :value="item.id"
                            v-bind:key="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item class="submit">
                <el-button type="primary" @click="submitForm('form')">保 存</el-button>
                <el-button @click="resetForm('form')">重 置</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
import reply from '@/models/reply'

export default {
  data() {
    return {
      status_arr: [
        { id: 1, name: '首次关注' },
        { id: 2, name: '没有关键字' },
        { id: 3, name: '首次关注或者没有关键字' },
        { id: 4, name: '关键字' },
      ],
      form: {
        title: '',
        status: 1,
        typeid: '1',
      },
    }
  },
  created() {
  },
  methods: {
    async submitForm() {
      const self = this
      // eslint-disable-next-line no-unused-vars
      const info = {
        title: self.form.title,
        status: self.form.status,
        typeid: self.form.typeid,
      }
      try {
        // eslint-disable-next-line no-unused-vars
        const res = await reply.addReply(info)
        if (res.error_code === 0) {
          this.$message.success(`${res.msg}`)
          this.back()
        }
      } catch (error) {
        console.log(error)
      }
    },
    // 重置表单
    resetForm(formName) {
      this.$refs[formName].resetFields()
    },
    back() {
      this.$emit('addClose')
    },
  },
}
</script>

<style lang="scss" scoped>
    .el-divider--horizontal {
        margin: 0
    }

    .container {
        .title {
            height: 59px;
            line-height: 59px;
            color: $parent-title-color;
            font-size: 16px;
            font-weight: 500;
            text-indent: 40px;

            .back {
                float: right;
                margin-right: 40px;
                cursor: pointer;
            }
        }

        .wrap {
            padding: 20px;
        }

        .submit {
            float: left;
        }
    }
</style>
